﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using WindowsFormsApplication3;

namespace bsy
{
    public partial class sy_selecemp_Form : Form
    {
        //连接字符串
        private string connStr = Properties.Settings.Default.bsyConnectionString;

        public sy_selecemp_Form()
        {
            InitializeComponent();
        }

        private string empId;

        public string EmpId
        {
            get { return empId; }
            set { empId = value; }
        }

        private string empName;

        public string EmpName
        {
            get { return empName; }
            set { empName = value; }
        }


        private void sy_selecemp_Form_Load(object sender, EventArgs e)
        {
            show_sy_selectemp_dgv("");
        }

        //显示员工列表
        private void show_sy_selectemp_dgv(string keyword)
        {

            string sql = string.Format("select EMP_id ID,munber 编号,name 姓名,phone 联系电话 from EMP where name like '%{0}%'",keyword);
            DataSet ds = new DataSet();
            ds = CommonDB.Query(sql);
            if (ds.Tables[0].Rows.Count > 0)
            {
                this.sy_selectemp_dgv.DataSource = ds.Tables[0].DefaultView;
                this.sy_selectemp_dgv.Columns[0].Visible = false;//第一列不显示
            }
            ds.Dispose();
        }

        //双击员工表
        private void sy_selectemp_dgv_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {

            }
            else
            {
                empId = this.sy_selectemp_dgv.Rows[e.RowIndex].Cells[0].Value.ToString();
                empName = this.sy_selectemp_dgv.Rows[e.RowIndex].Cells[2].Value.ToString();

                this.DialogResult = DialogResult.OK;
                this.Close();

            }
        }

        private void search_Click(object sender, EventArgs e)
        {
            if (string.Empty != keyword.Text)
            { 
               show_sy_selectemp_dgv(keyword.Text.ToString().Trim());
            
            }else{
                show_sy_selectemp_dgv("");
            }
        }

    }
}
